1
|
|
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
package bexee.wsdl;
|
10
|
|
|
11
|
|
import java.util.Iterator;
|
12
|
|
import java.util.List;
|
13
|
|
import java.util.Map;
|
14
|
|
|
15
|
|
import javax.wsdl.Binding;
|
16
|
|
import javax.wsdl.BindingFault;
|
17
|
|
import javax.wsdl.BindingInput;
|
18
|
|
import javax.wsdl.BindingOperation;
|
19
|
|
import javax.wsdl.BindingOutput;
|
20
|
|
import javax.wsdl.Definition;
|
21
|
|
import javax.wsdl.Fault;
|
22
|
|
import javax.wsdl.Input;
|
23
|
|
import javax.wsdl.Operation;
|
24
|
|
import javax.wsdl.Output;
|
25
|
|
import javax.wsdl.Port;
|
26
|
|
import javax.wsdl.PortType;
|
27
|
|
import javax.wsdl.Service;
|
28
|
|
import javax.wsdl.WSDLException;
|
29
|
|
import javax.wsdl.extensions.ExtensibilityElement;
|
30
|
|
import javax.wsdl.extensions.ExtensionRegistry;
|
31
|
|
import javax.wsdl.extensions.soap.SOAPAddress;
|
32
|
|
import javax.wsdl.extensions.soap.SOAPBinding;
|
33
|
|
import javax.wsdl.extensions.soap.SOAPBody;
|
34
|
|
import javax.wsdl.extensions.soap.SOAPFault;
|
35
|
|
import javax.wsdl.extensions.soap.SOAPOperation;
|
36
|
|
import javax.xml.namespace.QName;
|
37
|
|
|
38
|
|
import bexee.util.Constants;
|
39
|
|
|
40
|
|
|
41
|
|
|
42
|
|
|
43
|
|
|
44
|
|
|
45
|
|
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
public class WSDLBindingFactory {
|
50
|
|
|
51
|
|
|
52
|
|
|
53
|
|
|
54
|
|
|
55
|
|
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
0
|
public Definition addBinding(Definition definition, String uri)
|
61
|
|
throws WSDLException {
|
62
|
|
|
63
|
0
|
ExtensionRegistry extReg = definition.getExtensionRegistry();
|
64
|
|
|
65
|
|
|
66
|
0
|
Map portTypes = definition.getPortTypes();
|
67
|
0
|
for (Iterator iter = portTypes.values().iterator(); iter.hasNext();) {
|
68
|
0
|
PortType portType = (PortType) iter.next();
|
69
|
|
|
70
|
|
|
71
|
0
|
Binding binding = getBinding(portType, definition);
|
72
|
0
|
definition.addBinding(binding);
|
73
|
|
|
74
|
|
|
75
|
0
|
definition
|
76
|
|
.addService(getService(binding, portType, definition, uri));
|
77
|
|
}
|
78
|
|
|
79
|
|
|
80
|
0
|
definition.addNamespace(Constants.WSDL_SOAP_PPREFIX,
|
81
|
|
Constants.URI_WSDL_SOAP);
|
82
|
0
|
definition.addNamespace(Constants.WSDL_PRFIX, Constants.URI_WSDL);
|
83
|
|
|
84
|
0
|
return definition;
|
85
|
|
}
|
86
|
|
|
87
|
0
|
private Service getService(Binding binding, PortType portType,
|
88
|
|
Definition def, String uri) throws WSDLException {
|
89
|
|
|
90
|
0
|
ExtensionRegistry extReg = def.getExtensionRegistry();
|
91
|
|
|
92
|
|
|
93
|
0
|
Service service = def.createService();
|
94
|
0
|
service.setQName(new QName(portType.getQName().getNamespaceURI(),
|
95
|
|
portType.getQName().getLocalPart() + Constants.SERVICE_SUFFIX));
|
96
|
|
|
97
|
|
|
98
|
0
|
Port port = def.createPort();
|
99
|
0
|
port.setBinding(binding);
|
100
|
0
|
port.setName(portType.getQName().getLocalPart());
|
101
|
0
|
service.addPort(port);
|
102
|
|
|
103
|
|
|
104
|
0
|
SOAPAddress soapAddress = (SOAPAddress) extReg.createExtension(
|
105
|
|
Port.class, Constants.SOAP_ADDRESS_QNAME);
|
106
|
0
|
soapAddress.setLocationURI(uri);
|
107
|
0
|
port.addExtensibilityElement(soapAddress);
|
108
|
|
|
109
|
0
|
return service;
|
110
|
|
}
|
111
|
|
|
112
|
0
|
private Binding getBinding(PortType portType, Definition def)
|
113
|
|
throws WSDLException {
|
114
|
|
|
115
|
0
|
ExtensionRegistry extReg = def.getExtensionRegistry();
|
116
|
|
|
117
|
|
|
118
|
0
|
Binding binding = def.createBinding();
|
119
|
0
|
binding.setUndefined(false);
|
120
|
0
|
binding.setQName(new QName(portType.getQName().getNamespaceURI(),
|
121
|
|
portType.getQName().getLocalPart()
|
122
|
|
+ Constants.SOAP_BINDING_SUFFIX));
|
123
|
0
|
binding.setPortType(portType);
|
124
|
|
|
125
|
|
|
126
|
0
|
SOAPBinding soapBinding = (SOAPBinding) extReg.createExtension(
|
127
|
|
Binding.class, Constants.SOAP_BINDING_QNAME);
|
128
|
0
|
soapBinding.setStyle(bexee.util.Constants.DEFAULT_STYLE);
|
129
|
0
|
soapBinding.setTransportURI(bexee.util.Constants.URI_SOAP_HTTP);
|
130
|
|
|
131
|
|
|
132
|
0
|
binding.addExtensibilityElement(soapBinding);
|
133
|
|
|
134
|
|
|
135
|
0
|
List operations = portType.getOperations();
|
136
|
0
|
for (Iterator iterator = operations.iterator(); iterator.hasNext();) {
|
137
|
0
|
Operation operation = (Operation) iterator.next();
|
138
|
0
|
binding.addBindingOperation(getBindingOperation(operation, def));
|
139
|
|
}
|
140
|
|
|
141
|
0
|
return binding;
|
142
|
|
}
|
143
|
|
|
144
|
0
|
private BindingOperation getBindingOperation(Operation operation,
|
145
|
|
Definition definition) throws WSDLException {
|
146
|
|
|
147
|
|
|
148
|
0
|
ExtensionRegistry extReg = definition.getExtensionRegistry();
|
149
|
|
|
150
|
|
|
151
|
0
|
BindingOperation bindingOper = definition.createBindingOperation();
|
152
|
0
|
BindingInput bindingInput = definition.createBindingInput();
|
153
|
0
|
BindingOutput bindingOutput = definition.createBindingOutput();
|
154
|
|
|
155
|
|
|
156
|
0
|
bindingOper.setName(operation.getName());
|
157
|
0
|
bindingOper.setOperation(operation);
|
158
|
|
|
159
|
|
|
160
|
0
|
SOAPOperation soapOper = (SOAPOperation) extReg.createExtension(
|
161
|
|
BindingOperation.class, Constants.SOAP_OPERATION_QNAME);
|
162
|
0
|
soapOper.setSoapActionURI("");
|
163
|
0
|
bindingOper.addExtensibilityElement(soapOper);
|
164
|
|
|
165
|
|
|
166
|
0
|
bindingOper.setBindingInput(getBindingInput(operation.getInput(),
|
167
|
|
definition));
|
168
|
|
|
169
|
|
|
170
|
0
|
bindingOper.setBindingOutput(getBindingOutput(operation.getOutput(),
|
171
|
|
definition));
|
172
|
|
|
173
|
|
|
174
|
0
|
Map faults = operation.getFaults();
|
175
|
0
|
for (Iterator iter = faults.values().iterator(); iter.hasNext();) {
|
176
|
0
|
Fault fault = (Fault) iter.next();
|
177
|
0
|
bindingOper.addBindingFault(getBindingFault(fault, definition));
|
178
|
|
}
|
179
|
|
|
180
|
0
|
return bindingOper;
|
181
|
|
}
|
182
|
|
|
183
|
0
|
private BindingInput getBindingInput(Input input, Definition definition)
|
184
|
|
throws WSDLException {
|
185
|
|
|
186
|
|
|
187
|
0
|
BindingInput bindInput = definition.createBindingInput();
|
188
|
0
|
bindInput.setName(input.getMessage().getQName().getLocalPart());
|
189
|
|
|
190
|
0
|
bindInput.addExtensibilityElement(getSOAPBody(bindInput.getClass(),
|
191
|
|
definition));
|
192
|
|
|
193
|
0
|
return bindInput;
|
194
|
|
}
|
195
|
|
|
196
|
0
|
private BindingOutput getBindingOutput(Output output, Definition definition)
|
197
|
|
throws WSDLException {
|
198
|
|
|
199
|
|
|
200
|
0
|
BindingOutput bindOutput = definition.createBindingOutput();
|
201
|
0
|
bindOutput.setName(output.getMessage().getQName().getLocalPart());
|
202
|
|
|
203
|
0
|
bindOutput.addExtensibilityElement(getSOAPBody(bindOutput.getClass(),
|
204
|
|
definition));
|
205
|
0
|
return bindOutput;
|
206
|
|
}
|
207
|
|
|
208
|
0
|
private BindingFault getBindingFault(Fault fault, Definition definition)
|
209
|
|
throws WSDLException {
|
210
|
|
|
211
|
0
|
BindingFault bindingFault = definition.createBindingFault();
|
212
|
0
|
bindingFault.setName(fault.getName());
|
213
|
0
|
bindingFault.addExtensibilityElement(getSOAPFault(bindingFault,
|
214
|
|
definition));
|
215
|
|
|
216
|
0
|
return bindingFault;
|
217
|
|
|
218
|
|
}
|
219
|
|
|
220
|
0
|
private ExtensibilityElement getSOAPBody(Class clazz, Definition definition)
|
221
|
|
throws WSDLException {
|
222
|
|
|
223
|
|
|
224
|
0
|
ExtensionRegistry extReg = definition.getExtensionRegistry();
|
225
|
|
|
226
|
|
|
227
|
0
|
SOAPBody soapBody = (SOAPBody) extReg.createExtension(clazz
|
228
|
|
.getInterfaces()[0], Constants.SOAP_BODY_QNAME);
|
229
|
|
|
230
|
|
|
231
|
0
|
soapBody.setUse(Constants.DEFAULT_USE);
|
232
|
0
|
soapBody.setEncodingStyles(Constants.ENCODING_STYLES);
|
233
|
0
|
soapBody.setNamespaceURI(definition.getTargetNamespace());
|
234
|
|
|
235
|
0
|
return soapBody;
|
236
|
|
}
|
237
|
|
|
238
|
0
|
private SOAPFault getSOAPFault(BindingFault fault, Definition definition)
|
239
|
|
throws WSDLException {
|
240
|
|
|
241
|
|
|
242
|
0
|
ExtensionRegistry extReg = definition.getExtensionRegistry();
|
243
|
|
|
244
|
0
|
SOAPFault soapFault = (SOAPFault) extReg.createExtension(
|
245
|
|
BindingFault.class, Constants.SOAP_FAULT_QNAME);
|
246
|
|
|
247
|
0
|
soapFault.setUse(Constants.DEFAULT_USE);
|
248
|
0
|
soapFault.setEncodingStyles(Constants.ENCODING_STYLES);
|
249
|
|
|
250
|
0
|
return soapFault;
|
251
|
|
}
|
252
|
|
|
253
|
|
}
|